﻿using MediatR;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Application.Command.DepartmentCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.BuildingManagementCommandHandler
{
    public class BuildingManagementCreateCommandHandler : IRequestHandler<BuildingManagementCreateCommand, Results<int>>
    {
        private readonly IBuildingManagementService buildingManagementService;

        public BuildingManagementCreateCommandHandler(IBuildingManagementService buildingManagementService)
        {
            this.buildingManagementService = buildingManagementService;
        }

        public async Task<Results<int>> Handle(BuildingManagementCreateCommand request, CancellationToken cancellationToken)
        {
            var entity = new BuildingManagement
            {
                BuildingManagementId = request.BuildingManagementId,
                BuildingName = request.BuildingName,
                BuildingType=request.BuildingType,
                BuildingDuty = request.BuildingDuty,
                ProductionPeason = request.ProductionPeason,
                BuildingState = request.BuildingState==1?true:false,
                 AddName = request.AddName, 
                  UpdateName = request.UpdateName,
                   DelTime = DateTime.Now,   
                    AddTime =DateTime.Now,
                     DelName = request.DelName,
                      IsDel = 0,    
                       Remarks = request.Remarks,   
                        UpdateTime = DateTime.Now,
            };
            var list = await buildingManagementService.AddBuildingManagement(entity);
            return Results<int>.DataResult(list);
        }
    }

}
